Skip to content

genui: Tufte components (SmallMultiples, Slopegraph, Metric trend/vs, Chart notes) - #468

Draft
mjsz wants to merge 6 commits into
feat/genui-tuftefrom
feat/genui-tufte-components
Draft

mjsz wants to merge 6 commits into
feat/genui-tuftefrom
feat/genui-tufte-components

Conversation

@mjsz

@mjsz mjsz commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Adds four Tufte components to genui: SmallMultiples, Slopegraph, and two new Metric and Chart params, Metric trend/vs and Chart notes. Agents learn about them only from the Tufte style section and ui_examples. Sessions with Tufte style off get the same instructions and reference text as today, byte for byte. Builds on #467 (Tufte style behind a setting).

Signatures

  • SmallMultiples(type: line|area|bar, labels, series, unit?, sort?: total|last, columns?): one small chart per series (2 to 24 panels), every panel on the same y scale. series is {name: numbers | {values, tone}}.
  • Slopegraph(items, labels, unit?): items is [{name, before, after, tone?}] (up to 30), and labels holds the two column labels.
  • Metric(label, value, note?, tone?, trend?, vs?): trend is a list of numbers. vs is {value, label?, better?: higher|lower} or a bare value.
  • Chart(…, notes?): notes is [{at, text, series?}], on line, area and bar charts.

All four also take the unlisted source:, as Chart, Table and Metric do.

What each draws

  • SmallMultiples:
    • All panels share one scale, computed from the lowest and highest value across them. This is what the component is for, so tests check it explicitly.
    • Panels are the same size. The range frame appears only on the left column and the x labels only on the bottom row. Each panel's name sits at its top left.
    • Each panel is the existing XYChart with a panel layout, so it reuses range frames, single-series ink and the hover readout. Columns drop on narrow screens.
  • Slopegraph:
    • Each line runs between two columns on one scale, with the name and value at both ends.
    • spreadLabels keeps the names in each column apart, and a hairline links any name it moved back to its point.
    • Lines are drawn in ink. The accent goes on the largest change, or on the items that have a tone. When the graph is narrow, the right column shows values only.
    • The graph is left-aligned, and its columns are never more than 240 px apart (MAX_SLOPE_WIDTH). That keeps a full-range change at 28° or steeper, so a wide card doesn't flatten the slopes.
  • Metric trend/vs:
    • trend draws a word-sized Sparkline next to the value.
    • vs prints the change, such as "+12% vs last week", or the difference in points when the value is a percentage. It's green or red only when better is given.
    • Numbers can be written as text ("18.2k", "420 ms"); readNumber extends numberLike to read them.
  • Chart notes:
    • Each note is a few words next to its point, with a hairline leader and a halo in the page colour so it stays readable over bars and lines.
    • placeNotes keeps notes left of the series names at the line ends, moves each note up past any bar or line its text would sit on, and stacks neighbours with spreadLabels. A group that can't fit drops its last notes, so notes never overlap.
    • The chart grows only by the room its highest note needs above the plot (layoutNotes). That's zero when every note fits inside the plot.

Each component has:

  • A reader in core/tufte.ts, shared by the renderer, the markdown fallback and check_ui.
  • check_ui errors (tufteProblems) that name the field to fix.
  • Gallery examples, at least two per component, including an edge case.
  • A note in ui_examples.
  • A markdown fallback: SmallMultiples gives each panel's last value and range on the shared scale, Slopegraph gives before, after and change, Metric appends the change and trend, and Chart lists notes under its table.
  • An architecture.md section and a CHANGELOG entry.

Token rule

  • Catalog params and components can now be flagged tufte. Flagged ones are left out of the reference and its signatures. ui_examples prints the full signatures.
  • instructions-off.test.ts holds UI_REFERENCE, UI_REFERENCE_MORE, CODE_WORK_INSTRUCTIONS, AGENT_INSTRUCTIONS and AGENT_INSTRUCTIONS_WEB_OFF against snapshots written before any of this. An instructions test checks that each Tufte component is missing from the base text and present in the Tufte section.
  • The new components and params parse and render whatever the setting, and always in the Tufte style. If an agent writes one, the user gets the component that was asked for.

The Tufte style section (2,075 characters, up from 1,025):

# Inline UI: Tufte style
Tufte style is on: show data the way Edward Tufte would. This refines the Inline UI section.
- Context: compare every number with something (prior period, target, peer). Metric(label, value, trend?: numbers, vs?: {value, label, better: higher|lower}) draws its recent course as a word-sized sparkline and its change, green or red by which way is better.
- Label the graphic, not a key: units on every value, series named, and a few words at the points that matter, Chart(…, notes: [{at: label, text, series?}]), so the block reads without the prose.
- Small multiples: several entities or series → SmallMultiples(type: line|area|bar, labels, {name: numbers}, unit?, sort?: total|last, columns?), every panel on one scale, or a Table with a Sparkline per row; never one crowded Chart.
- Each item at two moments or under two conditions (before/after, 2024/2025) → Slopegraph([{name, before, after, tone?}], [left, right], unit?).
- Density: a lone number belongs in the sentence, not in a Metric. Several facts about one thing → one Table or KeyValue, not a Card each.
- Ink only for data: no decorative Icon or Badge; a tone only where it means good, bad or over a limit.
- Every Chart, Table and Metric says where its numbers came from: Load(path) or source:.
- Mechanism: when the user asks why, show what causes the number in a Diagram, not only the number.
Full APIs: ui_examples(["SmallMultiples", "Slopegraph", "Metric", "Chart"]). Examples:
```ui
Card("Checkout converts better since May", [Row([Metric("Conversion", "3.4%", trend: [2.9, 3.1, 3.0, 3.4], vs: {value: "3.1%", label: "May", better: "higher"}), Metric("p95", "420 ms", vs: {value: 380, label: "May", better: "lower"})])])
```
```ui
Card("Billing errors spiked at noon", [SmallMultiples("line", ["00", "06", "12", "18"], {api: [2, 4, 6, 3], billing: [3, 40, 62, 6], search: [0, 1, 2, 1]}, sort: "last")])
```
```ui
Card("The cache cut web builds most", [Slopegraph([{name: "web", before: 182, after: 64}, {name: "api", before: 96, after: 71}], ["Before", "After"], unit: "s")])
```

Unchanged output

Snapshots written before any change hold the rendered output:

Sparkline and smoothPath moved, unchanged, into sparkline.tsx. Importing Chart.tsx from display.tsx created an import cycle through inputs.tsx, which left a module-level constant undefined.

Things to check

  • The parameter names: before/after (matching Benchmark), vs.better, notes[].at, and sort: total|last.
  • at matches a label first, then a position, so at: 2019 finds the label "2019".
  • The /ui skill's Tufte part grows with the section. It's gated by the setting check, so users with Tufte style off don't follow it.

Tests

  • npm run typecheck: clean
  • npm test: 103 files, 1,286 tests passed
  • bb plugin build: succeeds
  • Screenshots of every new gallery example in light, dark and narrow width, reviewed by eye. Review fixes: notes now get a halo, Slopegraph shows leaders for moved names, Slopegraph's column gap is capped, and note headroom is sized to the notes.

🤖 Generated with Claude Code

mjsz and others added 6 commits December 1, 2026 21:36
…components

The Tufte components add parameters to Metric and Chart and teach
everything through the Tufte style section, so three things must not
change: the instructions and reference that sessions with Tufte style
off receive, Chart calls without notes (now held with the setting on as
well as off), and Metric calls without trend or vs, in either style.
These files are written from the code as it is before any of that.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Chart takes `notes: [{at, text, series?}]`: a few words by the point
they explain, joined to it by a hairline, with a dot on the point. `at`
is a label, or a position from 0 when no label matches; a note without
`series` points at the highest mark there. A note sits a line above its
point and moves up past any bar or line its text would sit on.
placeNotes (chartMath.ts) keeps notes left of the names at the lines'
ends and stacks notes that would touch with spreadLabels; a run that
can't fit drops its last notes, so none overlap. The chart grows only
by the room its highest note needs above the plot (layoutNotes), none
when every note fits inside it, and each note has a halo in the page's
colour where it crosses ink.

This also lays the ground the other Tufte components share:
- a `tufte` flag on catalog params and components keeps them out of the
  reference every session gets (instructions-off snapshots hold that
  text unchanged); ui_examples prints full signatures.
- core/tufte.ts reads every Tufte component and param for the renderer,
  the markdown form and check_ui, which now reports what they can't
  draw. numberLike moves there, with readNumber.
- XYChart takes a `panel` layout for SmallMultiples.

Chart calls without notes draw as before in either style (charts-on and
charts-off snapshots). Markdown lists notes under the chart's table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SmallMultiples(type, labels, series, unit?, sort?, columns?) draws one
small line, area or bar chart per series, 2 to 24 of them. Every panel
is drawn on the lowest and highest value of all panels, so a 10 in one
sits as low as a 10 in any other: comparison across the grid is the
point. Panels are the same size and keep the same margins; the y range
frame is on the left column only, the x labels on panels with none
under them, and each panel's name sits at its top left. `sort` (total,
last) puts the largest first; `columns` sets the grid, which drops
columns below 150 px a panel.

Each panel is an XYChart with a `panel` layout, so it reuses the range
frames, single-series ink and hover readout. It is drawn in the Tufte
style whatever the setting. check_ui reports a single panel, a panel
without numbers or more than 24; markdown is a table of each panel's
latest value and range on the shared scale. Three gallery examples
(lines, sorted bars in two columns, and one service's spike dwarfing
the rest) and ui_examples notes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Metric takes `trend` (numbers, drawn as a word-sized Sparkline beside
the value) and `vs` ({value, label?, better?: higher|lower}, or the bare
value): the change from a prior value or a target, "+12% vs last week",
in points when the value is a percentage, green or red only when
`better` says which way is good. Values read as numbers when written
as text ("18.2k", "420 ms", "99.9%"), with readNumber.

Metric calls without them draw exactly as before, in either style
(metric snapshots). Sparkline and the smooth line it shares with the
charts move, unchanged, to sparkline.tsx: display.tsx importing
Chart.tsx closed an import cycle through inputs.tsx that left a
module-level constant undefined. check_ui reports a vs or trend it
can't read; markdown adds the change and the trend after the note.
Two gallery examples (trends against prior weeks; targets in points,
no change, and a bare value) and ui_examples notes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Slopegraph(items, labels, unit?) draws items [{name, before, after,
tone?}] at two moments or under two conditions as lines between two
columns on one scale, so rank and change read together. Each end is
named with its value; spreadLabels moves names that would touch apart,
each column on its own, with a hairline back to the point when one
moved. When it is narrower than the names need, the right end keeps its
values and the names stay on the left. Lines are muted ink; the accent
goes on the largest change, or, when any item has a tone, on the toned
items only.

The graph is left-aligned and its columns are never more than 240 px
apart. A slope is read by its angle, and angles are judged best near
45° (Cleveland's banking): on the shortest plot, 128 px between the
highest and lowest value, 240 px keeps a change across the whole range
at 28° and half of it at 15°, and taller plots only steepen them. On a
600 px card the same changes would flatten to 12° and 6°.

Drawn in the Tufte style whatever the setting. check_ui reports bad
labels, items without numbers or names, unknown fields and more than
30 items; markdown is a table of both values and the change. Two
gallery examples (build times before and after a cache, and incident
causes with tones and close values) and ui_examples notes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Tufte style section (2,075 characters, up from 1,025) is the only
instruction text that names the new components: Metric trend and vs,
Chart notes, SmallMultiples and Slopegraph, each with its call, and
three one-line examples (metrics against May, a small-multiples spike,
a before/after slopegraph). It points at ui_examples for their full
APIs. Sessions with Tufte style off get byte-identical instructions and
reference (instructions-off snapshots); the reference leaves the Tufte
components out, and a test checks that each is taught in the section
instead. The section's examples compile like the rules'. The /ui
skill's Tufte part follows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mjsz
mjsz force-pushed the feat/genui-tufte-components branch from f25c172 to 1ddb8e9 Compare December 2, 2026 03:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant